﻿Public Class SedimSite

    Dim db As New Connexion
    Dim action As String
    Dim Entrer As String
    Dim TextBoxID As String
    Public databaseName As String
    Private Sub SedimSite_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ComboBoxCodeCatg.Visible = False
        majCatg()
    End Sub

    Private Sub majCatg()
        Try
            Entrer = ""
            db.myReq = "Select * FROM  [dbo].[SedimTyp2]"
            db.Connecter(databaseName)
            Me.ComboBoxCodeCatg.Items.Clear()
            Me.ComboBoxNomCatg.Items.Clear()
            Me.ComboBoxCodeCatg.Items.Add("")
            Me.ComboBoxNomCatg.Items.Add("Tous")

            While db.rdr.Read()
                Me.ComboBoxCodeCatg.Items.Add(db.rdr(0))
                Me.ComboBoxNomCatg.Items.Add(db.rdr(2))
            End While
            Me.ComboBoxCodeCatg.SelectedIndex = 0
            Me.ComboBoxNomCatg.SelectedIndex = 0
            db.Disconnecter()
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub

    Private Sub ComboBoxNomCatg_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxNomCatg.TextChanged

        If Me.ComboBoxNomCatg.FindString(Me.ComboBoxNomCatg.Text) > 0 Then
            Dim Pos As Int32 = Me.ComboBoxNomCatg.Text.Length
            Me.ComboBoxNomCatg.SelectedIndex = Me.ComboBoxNomCatg.FindString(Me.ComboBoxNomCatg.Text)
            Me.ComboBoxNomCatg.SelectionStart = Pos
            Me.ComboBoxNomCatg.SelectionLength = Me.ComboBoxNomCatg.Text.Length - Pos
            Me.ComboBoxCodeCatg.SelectedIndex = Me.ComboBoxNomCatg.FindString(Me.ComboBoxNomCatg.Text)
        Else
            Me.ComboBoxCodeCatg.Text = ""
        End If
    End Sub

    Private Sub ButtonNouv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNouv.Click
        Me.TextBoxDesc1.Text = ""
        Me.TextBoxNote.Text = ""
        Me.TextBoxSurf.Text = ""
        Me.TextBoxUnit.Text = ""
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim typ1 As New TypologieNiv1Form(databaseName)
        typ1.Text = "Type"
        typ1.Table = "SedimTyp2"
        typ1.Visible = True
    End Sub

    Private Sub ComboBoxNomCatg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBoxNomCatg.Click
        majCatg()
    End Sub

    Private Sub ButtonEnregistrer_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonEnregistrer.Click
        Try
            Dim idMax As Integer
            db.myReq = "INSERT INTO  [dbo].[SedimSit]([ID_Sit],[FrmDom_SedimSit],[CarFrm_SedimSit],[ExplFrm_SedimSit]) VALUES('" & db.idSite & "','" & Me.TextBoxDesc1.Text & "','" & Me.TextBoxDesc2.Text & "','" & Me.TextBoxDesc3.Text & "')"
            MsgBox(db.myReq)
            db.Connecter(databaseName)
            db.Disconnecter()
            db.myReq = "SELECT Max([Id_SedimSit]) FROM  [dbo].[SedimSit]"
            db.Connecter(databaseName)
            While db.rdr.Read
                idMax = db.rdr(0)
            End While
            db.Disconnecter()
            db.myReq = "INSERT INTO  [dbo].[SedimSitlFrn]([Id_SedimTyp],[Id_SedimSit],[Unit_SedimSitlFrn],[Suprf_SedimSitlFrn],[Desc_SedimSitlFrn]) VALUES('" & Me.ComboBoxCodeCatg.Text & "','" & idMax & "','" & Me.TextBoxUnit.Text & "','" & Me.TextBoxSurf.Text & "','" & Me.TextBoxNote.Text & "')"
            MsgBox(db.myReq)
            db.Connecter(databaseName)
            db.Disconnecter()
        Catch ex As Exception
            MsgBox("Problème de connexion")
        End Try
    End Sub
End Class